from menu_manager import MenuManager
from file_manager import FileManager
from student import Student
from event import *


class StudentManager:
    def __init__(self):
        self.menu_manager = MenuManager()
        self.event_manager = EventManager()
        self.event_manager.add_listener(UserListener())

    def run(self):
        while True:
            self.menu_manager.print_menu()
            option = input('请选择菜单：')

            try:
                if option == '1':
                    self.event_manager.fireEvents(Event('add'))

                if option == '2':
                    self.event_manager.fireEvents(Event('delete'))

                if option == '3':
                    self.event_manager.fireEvents(Event('update'))

                if option == '4':
                    self.event_manager.fireEvents(Event('add'))

                if option == '5':
                    self.event_manager.fireEvents(Event('query_all'))

                if option == '6':
                    self.event_manager.fireEvents(Event('sort'))

                if option == '0':
                    self.event_manager.fireEvents(Event('quit'))
                    break
            except Exception as e:
                print(e)


if __name__ == '__main__':
    student_manager = StudentManager()
    student_manager.run()
